import React, { useEffect, useState } from "react";
import "./My.css";
import axios from "axios";
import { useLocation, useNavigate } from "react-router-dom";

import "./my_info_desc.css";

export default function () {
  const [user, setuser] = useState(null);
  const location = useLocation();
  const queryState = new URLSearchParams(location.search);
  const id = queryState.get("id");
  const navigate = useNavigate();
  useEffect(() => {
    getUser();
  }, []);

  const getUser = async () => {
    try {
      const res = await axios.get("http://127.0.0.1:8000/loginInfo");
      console.log(res.data.data); // 确认返回的数据

      if (res.data.code === 200) {
        // 假设返回的是一个包含多个用户信息的数组
        setuser(res.data.data);
      }
    } catch (error) {
      console.log("我的..获取用户信息失败！" + error);
    }
  };
  return (
    <div className="my_info_desc">
      <div className="set-top">
        <span
          style={{ marginLeft: "20px", height: "50px", marginTop: "15px" }}
          onClick={() => navigate("/my")}
        >
          <svg
            t="1733574502891"
            class="icon"
            viewBox="0 0 1307 1024"
            version="1.1"
            xmlns="http://www.w3.org/2000/svg"
            p-id="4937"
            width="16"
            height="16"
          >
            <path
              d="M268.70922 566.468085h929.588652c36.312057 0 72.624113-29.049645 72.624114-72.624113 0-36.312057-29.049645-72.624113-72.624114-72.624114H305.021277l297.758865-297.758865c29.049645-29.049645 29.049645-72.624113 0-101.673759-29.049645-29.049645-72.624113-29.049645-101.673759 0L72.624113 450.269504c-14.524823 14.524823-21.787234 36.312057-21.787234 58.09929 0 21.787234 0 43.574468 21.787234 58.099291l428.48227 428.48227c29.049645 29.049645 72.624113 29.049645 101.673759 0 29.049645-29.049645 29.049645-72.624113 0-101.673759l-334.070922-326.808511z"
              fill=""
              p-id="4938"
            ></path>
          </svg>
        </span>
        <div
          className="set-right"
          style={{ marginLeft: "120px", fontSize: "18px", marginTop: "10px" }}
        >
          帖子详情
        </div>
      </div>

      <div className="my_info_desc_bigbox">
        <div className="bigbox_one">
          <div className="bigbox_one_left">
            <img src={user ? user.img_url : ""} alt="" />
          </div>
          <div className="bigbox_one_right">
            <div className="bigbox_one_right_one">
              {user ? user.name : "加载中..."}
            </div>
            <div className="bigbox_one_right_Two">
              {user ? user.times : "加载中..."}
            </div>
          </div>
        </div>
        <div className="bigbox_two">
          {user && user.dong_tai && Array.isArray(user.dong_tai) ? (
            user.dong_tai.map((item) => (
              <div key={item.id} className="bigbox_two_dong_tai_one">
                <div style={{ fontSize: "15px", marginBottom: "10px" }}>
                  {item.text}
                </div>
                <div> 
                <img src={item.img} alt="" />


                </div>
              </div>
            ))
          ) : (
            <span>暂无相关数据</span>
          )}
        </div>
      </div>
    </div>
  );
}
